package com.zxl.live.screen.screen.ui.helper.window;

import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.zxl.live.tools.alert.AlertPermissionUtils;
import com.zxl.live.tools.common.ApplicationHelper;

/**
 * Created by Administrator on 2017/11/8.
 */

public class WindowHelper extends BaseWindowHelper {

    private static WindowHelper sWindowHelper;

    private WindowManager.LayoutParams mWindowManagerParams;

    private WindowHelper(Context context) {
        super(context);
        mWindowManagerParams = new WindowManager.LayoutParams();
        if (AlertPermissionUtils.canAlert(context)) {
            mWindowManagerParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
        } else {
            mWindowManagerParams.type = WindowManager.LayoutParams.TYPE_TOAST;
        }
        mWindowManagerParams.format = PixelFormat.RGBA_8888; // 设置透明背景
        mWindowManagerParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        mWindowManagerParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        mWindowManagerParams.gravity = Gravity.CENTER;
        mWindowManagerParams.flags = 272; // WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
//                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }

    public static WindowHelper getWindowHelper() {
        if (null == sWindowHelper) {
            sWindowHelper = new WindowHelper(ApplicationHelper.getContext());
        }
        return sWindowHelper;
    }

    public void addView(View view) {
        super.addView(view, mWindowManagerParams);
    }
}
